

'use strict';

const express=require('express');
const path=require('path');
const xtpl=require('xtpl');
const moment=require('moment');

const db=require(path.join(__dirname,"../configs/database.js"));
const base=require(path.join(__dirname,"./baseController.js"));


// 订单表 有课程 有学生
module.exports.indentAdd=function(req,res){

  db.table('course').select().then(function(cData){

    db.table('student').select().then(function(sData){

    	console.log(cData);

         xtpl.renderFile(

            path.join(__dirname,"../views/admin/indent_add.html"),
            {
               crr:cData,
               srr:sData
            },
            function(err,content){

            	res.setHeader("Context-Type","text/html;charset=utf-8");
            	res.end(content);
            }

         	);
    });

  });
};

module.exports.indentAddData=function(req,res){
 let data={};
 db.table('indent').add(data).then(function(insertId){
     
 }).catch();

};


// 订单列表

module.exports.indentList=(req,res)=>{

const page=parseInt(req.query.page||'1');
const limit=parseInt(req.query.limit||'12');
const start=(page-1)*limit;


db.table('indent').count("*").then((count)=>{

  const totalPage=count%limit==0?count/limit:parseInt(count/limit)+1;
  const totalPageArray=[];
  for(var i=1;i<=totalPage;i++){

     totalPageArray.push(i);

  };
db.table('indent').select().then( (data)=>{

 data.indent_time=moment(data.indent_time*1000).format("YYYY-MM-DD");
 
  xtpl.renderFile(
   path.join(__dirname,"../views/admin/indent_list.html"),
   {
      indent:data,
      totalPage:totalPage,
      totalPageArray:totalPageArray,
      page:page
   },
   (err,content)=>{

      if(err){
        return console.log(err);
      }

      res.setHeader("Content-Type","text/html;charset=utf-8");
      res.end(content);

   }

    );

  });

});
  
};